<?php

class InviteAction extends Action{	
	var $groupinfo;
	function index(){
		$invIteInfo = $this->api->Invite_getInfo($this->mid,$_GET['code']);
		if($invIteInfo && $_GET['uid']){
			if(isJoinGroup($this->mid,$invIteInfo['typeid'])){   //如果已经加入，自动跳转至
				redirect( __APP__."Group/index/gid/{$invIteInfo['typeid']}");
			}else{
				$groupinfo = D('Group')->where('id='.$invIteInfo['typeid']." AND is_del=0")->find();
			    $this->groupinfo = $groupinfo;
                $this->assign('groupinfo',$groupinfo);
                $this->assign('inviteuid',$_GET['uid']);		
				$this->display();
			}
		}else{
			$this->error('邀请链接错误');
		}
	}
	
	//群组创建的邀请
	function create() {
		$this->groupinfo = D('Group')->where('id='.intval($_REQUEST['gid']))->find();
		$this->assign('groupinfo',$this->groupinfo);
		$from  = isset($_GET['from']) ? t($_GET['from']) : '';
		if($_POST['sendsubmit']) {
			
			$toUserIds = explode(",",$_POST["fri_ids"]);
    		$title_data['actor'] =  getUserName($this->mid);
			$body_data['actor'] = getUserName($this->mid);
			$body_data['mid'] = $this->mid;
			$body_data['title'] = $this->groupinfo['name'];
			$body_data['code'] = $this->api->Invite_getInviteLink('group',$this->groupinfo['id']);
    		//$body_data = getUserName($this->mid).'创建了一个群'.'<a href="{'.$this->appId.'}/Group/index/gid/'.$this->groupinfo['id'].'">'.$this->groupinfo['name']."</a>";
            //通知
            $cate = "notification";
            $this->api->notify_setAppId($this->appId);
            $this->api->notify_send($toUserIds,'group_create',$title_data,$body_data,$url,$cate);
        	
           
            $this->assign('sendCount',count($toUserIds));
			$this->display('create_invite_success');
			exit;
		}
		
		$this->assign('from',$from);
		$this->display();
	}
	
}


?>